package edu.ucsd.cse135.gas.bean;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import edu.ucsd.cse135.gas.logic.User;

public class RegistrationForm extends ActionForm {

	private String mail;
	private String password;
	private String password2;
	
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword2() {
		return password2;
	}
	public void setPassword2(String password2) {
		this.password2 = password2;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();
		
		if(!User.doesUserExist(mail))
		{
			errors.add("mail", new ActionMessage("error.mail.exists"));
		}
		
		if(!password.equals(password2))
		{
			errors.add("password", new ActionMessage("error.password.notEqual"));
		}
		
		return errors;
		
	}
	
}
